﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Ionic.Zip;
using System.IO;

namespace AbyssCombatLogger
{
    /// <summary>
    /// use BBot_Extractor.Extract_BBot();
    /// </summary>
    class BBot_Extractor
    {
        const string bbot_zip_file = "BBot.zip";
        /// <summary>
        /// 
        /// </summary>
        /// <returns>true if the extract went ok</returns>
        /// 
        private static string bBotFolder = null;

        public static bool BBotExists()
        {
            return System.IO.Directory.Exists(BBotFolder);
         
        }
        public static string BBotFolder
        {
            get
            {
                bBotFolder = Application.StartupPath + "\\";
                return bBotFolder;
            }
        }
        public static string BBotZipPath
        {
            get
            {
                return Application.StartupPath + "\\";
            }
        }

        public static bool Extract_BBot()
        {
            try
            {
                string bbot_file_path_name = BBotZipPath + bbot_zip_file;
                if (!File.Exists(bbot_file_path_name))
                {
                    return false;
                }

                ZipFile zip = ZipFile.Read(bbot_file_path_name);
                zip.FlattenFoldersOnExtract = false;
                foreach (ZipEntry e in zip)
                {
                    e.Extract(BBotFolder, ExtractExistingFileAction.OverwriteSilently);
                }
 


                zip.ExtractAll(BBotFolder, Ionic.Zip.ExtractExistingFileAction.OverwriteSilently);

                Properties.Settings.Default.FirstLoadBBot = false;
                Properties.Settings.Default.Save();
                return true;
            }
            catch (Exception e)
            {
                return false;
            }
        }
    }
}
